package com.link.base.base.wechat.controller;

import com.link.base.base.wechat.model.WxMedia;
import com.link.base.base.wechat.service.WxMediaService;
import com.link.base.wechat.mpnews.model.Article;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * WxMedia-微信素材中间表 
 *
 * @author 路江
 * @date 2019/05/22 10:12
 */
@Controller
@RequestMapping("/link/wxMedia")
public class WxMediaController extends BasicController<WxMedia> {
 
    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private WxMediaService wxMediaService;

    @Override
    public BasicService<WxMedia> getBasicService() throws Exception {
        return wxMediaService;
    }

    /**
     * 微信素材保存多公众号
     *
     * @author lujiang
     * @date 2019-05-22
     * @param articles
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/saveAndSendArticle", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> saveAndSendArticle(@RequestBody List<Article> articles) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            result = wxMediaService.saveAndSendArticle(articles);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("msg", e.getMessage());
        }
        return result;
    }

}
